package com.yidu.service.impl;

import com.yidu.dao.BookUserMapper;
import com.yidu.domain.BookUser;
import com.yidu.service.BookUserService;
import com.yidu.view.vo.BookUserVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;
import java.sql.Date;
import java.util.List;

/**
 * <p>@Description: No Description</p>
 * <p>@Author yidu-liandyao</p>
 * <p>@Date: 2021-01-12</p>
 * <p>@Time: 10:01</p>
 */
@Service
public class BookUserServiceImpl
        implements BookUserService {


    @Resource
    BookUserMapper mapper; //将dao取出

    @Override
    public List<BookUser> findAll(BookUserVo vo) {
        return mapper.findAll(vo);
    }

    @Override
    public int findCount(BookUserVo vo) {
        return mapper.findCount(vo);
    }

    @Override
    public int delete(Integer id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteAll(String ids) {
        //将,分隔的字符串分隔成数组,传入到dao中
        String[] idArray = ids.split(",");
        return mapper.deleteAll(idArray);
    }

    @Override
    public int insertSelective(BookUserVo vo) {
        BookUser po = new BookUser();
        //copy对象
        BeanUtils.copyProperties(vo,po);
        //单独将日期设置进去
        po.setUserBirthday(Date.valueOf(vo.getUserBirthday_()));

        return mapper.insertSelective(po);
    }

    @Override
    public BookUser selectByPrimaryKey(Integer userId) {
        return mapper.selectByPrimaryKey(userId);
    }

    @Override
    public int updateByPrimaryKeySelective(BookUserVo vo) {
        BookUser po = new BookUser();
        //copy对象
        BeanUtils.copyProperties(vo,po);
        //单独将日期设置进去
        po.setUserBirthday(Date.valueOf(vo.getUserBirthday_()));

        return mapper.updateByPrimaryKeySelective(po);
    }
}
